package com.xianbeiying.app.ckgl.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xianbeiying.app.ckgl.MyApplication;
import com.xianbeiying.app.ckgl.R;
import com.xianbeiying.app.ckgl.bean.MyCollectBean;
import com.xianbeiying.app.ckgl.bean.UrlBean;

/**
 * 我的收藏数据适配
 */
public class MyCollectListdapter extends BaseAdapter{

    private Context context;
    private MyCollectBean myCollectBean;
public MyCollectListdapter(Context context,MyCollectBean myCollectBean) {
        this.context = context;
        this.myCollectBean=myCollectBean;
        }

    @Override
    public int getCount() {
        return myCollectBean.getV().getCOLLECTIONS().size();
    }

    @Override
    public Object getItem(int position) {
        return getItem(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_my_collect, parent, false);
            holder = new ViewHolder();
            holder.view_collect_line1=(View) convertView.findViewById(R.id.view_collect_line1);
            holder.view_collect_line2=(View) convertView.findViewById(R.id.view_collect_line2);
            holder.view_collect_line3=(View) convertView.findViewById(R.id.view_collect_line3);
            holder.tv_collect_date=(TextView) convertView.findViewById(R.id.tv_collect_date);
            holder.tv_collect_title=(TextView) convertView.findViewById(R.id.tv_collect_title);
            holder.tv_collect_content=(TextView) convertView.findViewById(R.id.tv_collect_content);
            holder.img_collect=(ImageView) convertView.findViewById(R.id.img_collect);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        holder.view_collect_line1.setVisibility(View.GONE);
        holder.view_collect_line3.setVisibility(View.VISIBLE);
        if(position==0){
            holder.view_collect_line1.setVisibility(View.VISIBLE);
        }
        if(position==myCollectBean.getV().getCOLLECTIONS().size()){
            holder.view_collect_line3.setVisibility(View.GONE);
        }
        ImageLoader.getInstance().displayImage("http://"+ MyApplication.IP+UrlBean.IMAGES+myCollectBean.getV().getCOLLECTIONS().get(position).getIMAGEURL(), holder.img_collect);
        holder.tv_collect_title.setText(myCollectBean.getV().getCOLLECTIONS().get(position).getTITLE());
        holder.tv_collect_content.setText(myCollectBean.getV().getCOLLECTIONS().get(position).getCONTENT());
        holder.tv_collect_date.setText("");
        return convertView;
    }

    private class ViewHolder{
        View view_collect_line1,view_collect_line2,view_collect_line3;
        ImageView img_collect;
        TextView tv_collect_title;
        TextView tv_collect_date;
        TextView tv_collect_content;
    }
}
